Skip to content

Add support for PNG - #4

Merged
hohonuuli merged 21 commits into
mainfrom
task/add-png
Jun 22, 2026
Merged

hohonuuli merged 21 commits into
mainfrom
task/add-png

Conversation

@hohonuuli

Copy link
Copy Markdown
Member

Requested by @kwalz in mbari-org/dfg-tool#3

@hohonuuli hohonuuli self-assigned this Jun 21, 2026
@hohonuuli hohonuuli added the enhancement New feature or request label Jun 21, 2026
@hohonuuli

Copy link
Copy Markdown
Member Author

This is a starting point. I'll be adding code to this ...

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR generalizes frame capture and caching from JPEG-only to support both JPEG and PNG output, and exposes PNG capture via new API endpoints. It also updates the build/tooling to sbt 2.0.0 and refreshes several dependency/plugin versions.

Changes:

  • Introduce ImageType and update capture/cache types to work with multiple image formats (JPEG/PNG).
  • Extend ffmpeg invocation to emit PNGs when the target path ends in .png, and add new /capture/png endpoint.
  • Update tests and build/tooling (sbt 2, Scala 3.8.4, refreshed plugins/dependencies, workflow fixes).

Reviewed changes

Copilot reviewed 36 out of 38 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/test/scala/org/mbari/beholder/TestUtil.scala Ensures test video resource is usable even when packed into a JAR (sbt 2), by extracting to a temp file.
src/test/scala/org/mbari/beholder/SanitySuite.scala Removes unused JUnit imports as tests run under MUnit.
src/test/scala/org/mbari/beholder/JpegCacheSuite.scala Removes legacy JPEG-only cache tests (replaced by multi-type cache suite).
src/test/scala/org/mbari/beholder/JpegCache2Suite.scala Removes legacy cache v2 tests (replaced by multi-type cache suite).
src/test/scala/org/mbari/beholder/ImageCaptureSuite.scala Renames and updates capture test to use ImageCapture + ImageCacheImpl.
src/test/scala/org/mbari/beholder/ImageCacheImplSuite.scala Adds test coverage for JPEG, PNG, and mixed-type cache behavior.
src/test/scala/org/mbari/beholder/etc/jdk/PathUtilSuite.scala Adds useExtension test and retains URL/path tests.
src/test/scala/org/mbari/beholder/etc/ffmpeg/FfmpegUtilSuite.scala Adds png frame-capture test alongside jpg.
src/test/scala/org/mbari/beholder/CachedImageSuite.scala Updates tests to validate .jpg and .png path generation.
src/test/scala/org/mbari/beholder/api/CaptureEndpointsSuite.scala Updates endpoint tests to use new cache/capture types.
src/main/scala/org/mbari/beholder/util/VectorUtil.scala Minor formatting/line numbering change only.
src/main/scala/org/mbari/beholder/Main.scala Switches runtime wiring to ImageCacheImpl + ImageCapture; reorganizes imports.
src/main/scala/org/mbari/beholder/JpegCapture.scala Removes JPEG-only capture implementation (replaced by ImageCapture).
src/main/scala/org/mbari/beholder/JpegCache.scala Removes legacy JPEG-only cache implementation.
src/main/scala/org/mbari/beholder/ImageType.scala Adds image type enum (JPEG/PNG) with extensions and media types.
src/main/scala/org/mbari/beholder/ImageCapture.scala Adds image-type-aware capture implementation.
src/main/scala/org/mbari/beholder/ImageCacheImpl.scala Updates cache implementation to key by (elapsedMs, imageType) and scan both formats.
src/main/scala/org/mbari/beholder/ImageCache.scala Updates cache trait APIs to operate on CachedImage and include imageType in lookups/removals.
src/main/scala/org/mbari/beholder/etc/zio/ZioUtil.scala Import ordering only.
src/main/scala/org/mbari/beholder/etc/xml/Converters.scala Import grouping/formatting only.
src/main/scala/org/mbari/beholder/etc/jdk/PathUtil.scala Adds useExtension and isPng.
src/main/scala/org/mbari/beholder/etc/ffmpeg/FfmpegUtil.scala Adds command builder + execution wrapper and supports PNG output based on target extension.
src/main/scala/org/mbari/beholder/etc/ffmpeg/DurationString.scala Import ordering only.
src/main/scala/org/mbari/beholder/etc/circe/CirceCodecs.scala Removes an unused import.
src/main/scala/org/mbari/beholder/CachedImage.scala Renames Jpeg to CachedImage and supports parsing/paths for both jpg/png.
src/main/scala/org/mbari/beholder/AppConfig.scala Formatting only.
src/main/scala/org/mbari/beholder/api/SwaggerEndpoints.scala Import ordering only (but Swagger generation should include new endpoints).
src/main/scala/org/mbari/beholder/api/HealthStatus.scala Formatting only.
src/main/scala/org/mbari/beholder/api/HealthEndpoints.scala Import ordering only.
src/main/scala/org/mbari/beholder/api/Endpoints.scala Import ordering only.
src/main/scala/org/mbari/beholder/api/CaptureRequest.scala Removes unused imports.
src/main/scala/org/mbari/beholder/api/CaptureEndpoints.scala Adds /capture/jpg + /capture/png endpoints and shared logic with ImageCapture.
project/plugins.sbt Updates/modernizes sbt plugins and adds scalafix.
project/Dependencies.scala Bumps library versions and updates Scala 3 style.
project/build.properties Upgrades to sbt 2.0.0.
build.sbt Updates Scala version, enables semanticdb/scalafix support, and tweaks test options/build settings.
.github/workflows/test.yml Fixes Java version to 25 for CI.
.github/workflows/docs.yml Updates docs artifact path for Scala 3.8.4.
Comments suppressed due to low confidence (3)

src/main/scala/org/mbari/beholder/ImageCacheImpl.scala:71

  • evictionOrdering doesn't include imageType (or path) as a tie-breaker. If a JPEG and PNG share the same created timestamp (common on restart when filesystem timestamps have coarse resolution) and the same (videoUri, elapsedTime), the comparator returns 0 and ConcurrentSkipListSet will drop one entry, breaking mixed-type caching/eviction.
    src/main/scala/org/mbari/beholder/ImageCacheImpl.scala:111
  • put stores the stamped value (with updated created) but returns the original jpeg argument. This makes the method contract/documentation misleading and prevents callers from using the returned value as the canonical cache entry (e.g., for eviction ordering/debugging).
    src/main/scala/org/mbari/beholder/ImageCacheImpl.scala:145
  • The eviction log message still says "jpegs", but the cache now stores multiple image types (e.g., PNG). This will be misleading when debugging cache behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 40 out of 42 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (3)

src/main/scala/org/mbari/beholder/ImageCacheImpl.scala:69

  • evictionOrdering does not include imageType as a tie-breaker. With the new mixed-type cache key ((elapsedMs, ImageType)), two entries with the same created, videoUri, and elapsedTime but different imageType can compare as equal (0), causing ConcurrentSkipListSet to drop one entry and potentially break eviction/index consistency.
    src/main/scala/org/mbari/beholder/ImageCacheImpl.scala:112
  • put stamps created = Instant.now() into stamped and stores that in the index/eviction queue, but returns the original jpeg value. This makes the returned object inconsistent with what was actually stored (and with the scaladoc saying the stored image has updated creation time).
    src/main/scala/org/mbari/beholder/ImageCacheImpl.scala:33
  • The class scaladoc still describes this as a "JPEG frame cache" indexed by (videoUri, elapsedTime), but the implementation now supports multiple image types and indexes by (videoUri, elapsedTime, imageType). Updating the doc avoids misleading API consumers.

Comment thread .github/workflows/release.yml Resolved
@hohonuuli
hohonuuli merged commit 7b4e55b into main Jun 22, 2026
1 check passed
@hohonuuli
hohonuuli deleted the task/add-png branch June 22, 2026 18:11
@kwalz

kwalz commented Jun 23, 2026

Copy link
Copy Markdown

Issue with i2map video when new beholder is trying to grab frames in gridview, see screenshot, this worked last week for i2map in gridivew with old version of beholder (Kevin message from email: It seems Beholder is getting 500 errors when trying to grab frames from i2MAP footage).
Terminal error message:
Unexpected error fetching ROI for 019ee0f7-891c-74ec-a439-21d07df70c73: Server error '500 Internal Server Error' for url 'http://arwen.shore.mbari.org:8088/capture'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500
2026-06-22 14:49:41,189 [ERROR] vars-gridview: Error refreshing ROI for 019ee0f7-891c-74ec-a439-21d07df70c73: Failed to fetch ROI image
Unexpected error fetching ROI for 019ee0f7-891c-7a0e-aef6-e0891406b0b4: Server error '500 Internal Server Error' for url 'http://arwen.shore.mbari.org:8088/capture'

For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500
Screenshot 2026-06-22 at 2 50 37 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants